@echo off

if /i p%2%==pyizu (
   set profile=yizu
   goto module
)

rem 默认环境
echo "default"
set profile=test



:module
    if /i p%1%==pfintech-admin   goto redeploy
    if /i p%1%==pfintech-restful   goto redeploy
    if /i p%1%==pall goto allRedeploy

    echo Deploy command incorrect!
    echo Usage : tomcat-deploy.bat {fintech-admin ^|fintech-restful ^|all} [test ^| demo ^| uat ^| prod]
    goto end

:redeploy
    echo "update from Git"
    call git pull
    echo "rebuild.."
    set module=kylin-%1%

    rem call mvn -P%profile% clean package -pl %module% -DskipTests
    rem call mvn clean install -pl douhuu-core
    call mvn -P%profile% clean package tomcat7:redeploy -pl %module% -DskipTests
    if %errorlevel% == 0 (
        goto success
    )

goto fail

rem 一键全部发版本
:allRedeploy
    echo "update from Git"
    call git pull
    rem call mvn -P%profile% clean package install  -DskipTests
    set deployModule=kylin-admin kylin-h5app
    set count=0
    for %%m in (%deployModule%) do (
        call mvn -P%profile% clean package tomcat7:redeploy -pl %%m -DskipTests
        if %errorlevel% neq 0 (
           echo "Already Deploy %count% Modules!"
           goto fail
        )
        set /a count=count+1
    )
echo "Deploy %count% Modules Success!"
goto success

:success
echo Success Deploy
goto end

:fail
echo "Fail Deploy"
goto end

:end
